package hangzhou;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Page.pageBean;
import service.UserService;




/**
 * Servlet implementation class ShowUsersByPageServlet
 */
@WebServlet("/ShowUsersByPageServlet")
public class ShowUsersByPageServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//0.���ñ���
		//1.��ȡ�ڼ�ҳ
		  System.out.println("PageQuery");
		  int currPage;
		  //通过if判断数据到底来自servlet还是jsp有且只能来自一个。
		  //此处获取来自servlet的传递的数据要使用，getAttribute接收参数
		  if(request.getAttribute("currPage")!=null) {
			  
			  currPage=Integer.parseInt((String)request.getAttribute("currPage"));
			//此处获取来自jsp的传递的数据要使用，getParameter接收参数
		  }else if(request.getParameter("currPage")!=null) {
			  currPage=Integer.parseInt(request.getParameter("currPage"));
		  }else {
			  currPage=1;
		  }
		  System.out.println(currPage);
		    //�̶�ÿҳ��ʾ������
		    int pageSize=5;
		//2.����service��ɷ�ҳ��ѯ�����أ�pageBean
		   pageBean<denglu>  bean=new UserService().showProductsByPage(currPage,pageSize);
		//3.��pagebean����request���У�����ת��user_page.jsp,�����е����ݶ���װ��pb���ύ��ǰ��
		   request.setAttribute("pb", bean);
		   request.getRequestDispatcher("/kongzhitai.jsp").forward(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
